<?php


    // Author: Tomasz Durka
    // Creation date: 17th August 2009
    // Function prints out javascript code which fills span behind active_inputs
    
    
  function js_active_validation(ActiveRecord $obj) {
    
    if (!$obj->failed_validations())
      return;
    $class_name = get_class($obj);
    $obj_prefix = $obj->id ? "[{$obj->id}]" : '';
    $code = "<script language=\"javascript\">";
      foreach ($obj->failed_validations() as $attribute => $reason) {
        $code .= "$('{$class_name}{$obj_prefix}[{$attribute}]').next(0).show();";
        $code .= "$('{$class_name}{$obj_prefix}[{$attribute}]').next(0).update(\"" . $reason ."\");";
      } 
    $code .= "</script>";
    
    return $code;
    
  }

?>